package br.ucb.sigplan.action.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.ucb.sigplan.action.Action;
import br.ucb.sigplan.beans.Conteudo;
import br.ucb.sigplan.crud.ConteudoCrud;
import br.ucb.sigplan.crud.ConteudoTurmaCrud;
import br.ucb.sigplan.util.ConteudoUtil;

public class AbrirAlteraConteudoTurmaAction implements Action {

	@Override
	public String execute(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		Integer idTurma = new Integer(req.getParameter("idTurma"));
		List<Conteudo> conteudos = ConteudoCrud.findAll();
		List<Conteudo> conteudosTurma = ConteudoTurmaCrud.findConteudoByTurma(idTurma);
		ConteudoUtil.putConteudosTurma(conteudos, conteudosTurma);
		session.setAttribute("conteudos", conteudos);
		session.setAttribute("conteudosTurma", conteudosTurma);
		session.setAttribute("turma", idTurma);
		return "/jsp/professor/conteudo/profAlteraConteudoTurma.jsp";
	}

}
